//
//  LSNotiTableViewCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/19.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSNotiTableViewCell.h"

@interface LSNotiTableViewCell ()
@property (nonatomic, strong) UIImageView *mainImageView;
@property (nonatomic, strong) UILabel *mainTitleLabel;
@property (nonatomic, strong) UILabel *mainSubtitleLabel;
@property (nonatomic, strong) UIImageView *rightArrowImageView;
@end

@implementation LSNotiTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.rightArrowImageView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 5)];
        lineView.backgroundColor = hexColor(EEEEEE);
        [self.contentView addSubview:lineView];
        [self.contentView addSubview:self.mainImageView];
        [self.contentView addSubview:self.mainTitleLabel];
        [self.contentView addSubview:self.mainSubtitleLabel];
    }
    return self;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    WS
    if (highlighted) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    WS
    if (selected) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.contentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)setMainImageName:(NSString *)mainImageName {
    _mainImageName = mainImageName;
    self.mainImageView.image = [UIImage imageNamed:mainImageName];
}

- (void)setMainTitleText:(NSString *)mainTitleText {
    _mainTitleText = mainTitleText;
    self.mainTitleLabel.text = mainTitleText;
}

- (void)setMainSubtitleText:(NSString *)mainSubtitleText {
    _mainSubtitleText = mainSubtitleText;
    self.mainSubtitleLabel.text = mainSubtitleText;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    WS
    [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
        make.centerY.equalTo(weakSelf.contentView.mas_centerY).with.offset(3);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mainImageView.mas_right).with.offset(10);
        make.top.equalTo(weakSelf.mainImageView.mas_top).with.offset(2);
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-25);
    }];
    [self.mainSubtitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mainImageView.mas_right).with.offset(10);
        make.bottom.equalTo(weakSelf.mainImageView.mas_bottom).with.offset(-2);
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-25);
    }];
}

- (UIImageView *)mainImageView {
    if (!_mainImageView) {
        _mainImageView = [[UIImageView alloc] init];
    }
    return _mainImageView;
}

- (UILabel *)mainTitleLabel {
    if (!_mainTitleLabel) {
        _mainTitleLabel = [[UILabel alloc] init];
        _mainTitleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:15];
        _mainTitleLabel.textColor = hexColor(333333);
    }
    return _mainTitleLabel;
}

- (UILabel *)mainSubtitleLabel {
    if (!_mainSubtitleLabel) {
        _mainSubtitleLabel = [[UILabel alloc] init];
        _mainSubtitleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:13];
        _mainSubtitleLabel.textColor = hexColor(666666);
    }
    return _mainSubtitleLabel;
}

- (UIImageView *)rightArrowImageView {
    if (!_rightArrowImageView) {
        _rightArrowImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"jiantou"] changeWithNewTintColor:hexColor(999999)]];
        _rightArrowImageView.center = CGPointMake(ScreenWidth-20, (LSNotiTableViewCellHeight-10)/2+10);
    }
    return _rightArrowImageView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

@end
